package mysql.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("/args")
public class ArgsController {
    @Autowired
    private ApplicationArguments applicationArguments;

    @GetMapping("/test")
    public void test() {
        // 获取选项参数k-v
        for (String name : applicationArguments.getOptionNames()) {
            System.out.println(name);
            System.out.println(applicationArguments.getOptionValues(name));
        }
        // 获取非选项参数
        applicationArguments.getNonOptionArgs();
        // 获取系统参数
        System.getProperty("server.port");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true; // 自反性：x.equals(x) => true
        if (o == null || getClass() != o.getClass()) return false;
        ArgsController that = (ArgsController) o;
        return Objects.equals(applicationArguments, that.applicationArguments);
    }

    @Override
    public int hashCode() {
        return Objects.hash(applicationArguments);
    }
}
